package com.kuangchi.oam.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @version v1.0
 * @类描述：
 * @项目名称：
 * @包名： com.kuangchi.oam.utils
 * @类名称：RunCmdCommand
 * @创建人：YIHANG.XU
 * @创建时间：2021/6/231:34 下午
 * @修改人：YIHANG.XU
 * @修改时间：2021/6/231:34 下午
 * @修改备注：
 * @Copyright
 */
@Slf4j
public class RunCmdCommand {
    public static String CmdCommand(String command) {
        String result = null;
        try {
            Process ps = Runtime.getRuntime().exec(command);
            BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
            StringBuffer sb = new StringBuffer();
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line).append("\n");
            }
            result = sb.toString();
            log.info(result);
        } catch (Exception e) {
            log.error("----error-----");
            e.printStackTrace();
        }
        return result;

    }

    public static void main(String[] args) {
        String ls = CmdCommand("ls -a");
        System.out.println(ls);
    }

}
